const template = `
<div class="event-summary-main-btn">
       <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 48 48" width="29" height="29"><defs data-reactroot=""></defs><g><rect width="48" height="48" fill="white" fill-opacity="0.01"></rect><path d="M18 31H38V5" stroke="#63e7f4" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"></path><path d="M30 21H10V43" stroke="#63e7f4" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"></path><path d="M44 11L38 5L32 11" stroke="#63e7f4" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"></path><path d="M16 37L10 43L4 37" stroke="#63e7f4" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"></path></g></svg>

    <div class="event-summary-main-btn-label">变更事件</div>
  </div>
`;

const css = `
.event-summary-main-btn {
  color: #63e7f4;
  width: 100%;
  height: 100%;
  text-align: center;
}
.event-summary-main-btn-label {
  font-size: 12px;
  line-height: 12px
  margin-top: 4px;
}
`;




const form = this.getApiPage().retrievePlugin('base-forms')
const data = form.getFormData('form_20')
const obj = Object.keys(data).reduce((acc, key) => {
  if (data[key] !== '') {
    acc[key] = data[key];
  }
  return acc;
}, {});


const $form = this.getApiPage().getApiWidgetByAliasName('judge-content').widgetObj;
// 详情时隐藏上传显示
$form._option.config.forEach(v => {
  if (v.type == 'upload') {
    v.visible = false
  }

  if (v.dataIndex == 'sourceDeviceId') {
    v.visible = false
  }
})
console.log('$form', $form)
$form._option.isDetail = false
$form.render()
form.setFormData('form_20', $form._option.dataSource)


const options = {
  method: 'GET',
  headers: {
    "Content-type": "application/json",
  }
}
fetch(`/Basics/basics-main/system/equipmentObject/listDetailByEquipmentCode?equipmentTypeCode=camera&areaId=${$form.areaId}`, options)
  .then(res => res.json())
  .then(json => {
    if (json?.resultCode === '000000') {
      json.result.rows.forEach(i => {
        i.name = i.equipmentName;
        i.value = i.equipmentCode;
      });
      $form.asyncSelectOptions('sourceDeviceId', json.result.rows);
      $form.tempData = json.result.rows;
      form.setFormData('form_20', {
        sourceDeviceId: $form._option.dataSource.sourceDeviceId
      })
    }
  })
